//
//  DKContactAuthSigleView.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/11/27.
//

#import "DKContactAuthSigleView.h"
#import "DKContactAuthRelationView.h"
#import "DKContactAuthNameView.h"
#import "DKContactAuthMobileView.h"
#import "DKContactController.h"
@interface DKContactAuthSigleView()
@property (nonatomic,strong) UILabel *dk_ContactAuthTitleLab;
@property (nonatomic,strong) DKContactAuthRelationView *dk_ContactAuthRelationView;
@property (nonatomic,strong) DKContactAuthNameView *dk_ContactAuthNameView;
@property (nonatomic,strong) DKContactAuthMobileView *dk_ContactAuthMobileView;
@end
@implementation DKContactAuthSigleView
-(instancetype)init{
    if(self == [super init]){
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    self.dk_ContactAuthTitleLab = [[UILabel alloc] init];
    self.dk_ContactAuthTitleLab.textColor = DK_Hex(@"#999999");
    self.dk_ContactAuthTitleLab.font = DK_FONT_Regular(14);
    [self addSubview:self.dk_ContactAuthTitleLab];
    [self.dk_ContactAuthTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(20)));
    }];
    self.dk_ContactAuthRelationView = [[DKContactAuthRelationView alloc] init];
    [self addSubview:self.dk_ContactAuthRelationView];
    [self.dk_ContactAuthRelationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_ContactAuthTitleLab.mas_bottom).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_ContactAuthRelationView.SelectScuessBlock = ^{
        if(weakSelf.updataScuessBlock){
            weakSelf.updataScuessBlock();
        }
    };
    
    self.dk_ContactAuthNameView = [[DKContactAuthNameView alloc] init];
    [self addSubview:self.dk_ContactAuthNameView];
    [self.dk_ContactAuthNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_ContactAuthRelationView.mas_bottom).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_ContactAuthNameView.StartSelectContactBlock = ^{
//        //通讯录权限
//        [DKAuthorityHelper requestAddressBookAuthorization:^(DKAuthorizationStatus status) {
//            switch (status) {
//                case DKAuthorizationStatusAuthorized://已授权
//                {
                    DKContactController *dk_ContactCtrl = [[DKContactController alloc] init];
                    dk_ContactCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
                    [[weakSelf getTopViewController] presentViewController:dk_ContactCtrl animated:YES completion:^{}];
                    dk_ContactCtrl.SelectContactScuessBlock = ^(NSString * _Nonnull phoneNumber, NSString * _Nonnull name) {
                        weakSelf.dk_ContactAuthNameView.contactAuthName = name;
                        weakSelf.dk_ContactAuthMobileView.contactAuthMobile = phoneNumber;
                        if(weakSelf.updataScuessBlock){
                            weakSelf.updataScuessBlock();
                        }
                    };
//                }
//                    break;
//                default:
//                    [DKAlertHelper showMessage:@"No permission to enable, please enable permission"];
//                    break;
//            }
//        }];
        
    };
    self.dk_ContactAuthNameView.InputScuessBlock = ^{
        if(weakSelf.updataScuessBlock){
            weakSelf.updataScuessBlock();
        }
    };
    
    self.dk_ContactAuthMobileView = [[DKContactAuthMobileView alloc] init];
    [self addSubview:self.dk_ContactAuthMobileView];
    [self.dk_ContactAuthMobileView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_ContactAuthNameView.mas_bottom).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_ContactAuthMobileView.InputScuessBlock = ^{
        if(weakSelf.updataScuessBlock){
            weakSelf.updataScuessBlock();
        }
    };
}
- (NSString *)getContactAuthRelation{
    return [self.dk_ContactAuthRelationView getStepStatusSelect];
}
- (NSString *)getContactAuthName{
    return [self.dk_ContactAuthNameView getContactAuthName];
}
- (NSString *)getContactAuthMobile{
    return [self.dk_ContactAuthMobileView getContactAuthMobile];
}
-(void)setAuthContactAuthSigleType:(AuthContactAuthSigleType)authContactAuthSigleType{
    _authContactAuthSigleType = authContactAuthSigleType;
    self.dk_ContactAuthRelationView.authContactAuthSigleType = _authContactAuthSigleType;
    self.dk_ContactAuthNameView.authContactAuthSigleType = _authContactAuthSigleType;
    self.dk_ContactAuthMobileView.authContactAuthSigleType = _authContactAuthSigleType;
    if(_authContactAuthSigleType == AuthContactAuthSigleTypeContactFirst){
        self.dk_ContactAuthTitleLab.text = @"01- Contact";
    }else if (_authContactAuthSigleType == AuthContactAuthSigleTypeContactSecond){
        self.dk_ContactAuthTitleLab.text = @"02- Contact";
    }
}
@end
